<template>
    <div class="plug-container" @mousemove.prevent>
        <div class="plug-wrapper">
            <Input placeholder="搜一下" v-model="searchKey"></Input>

            <section class="one-plug">
                <h2>分类</h2>
                <ul class="milk-ul">
                    <li class="milk-li" v-for="(v,i) in categoryList" :key="i"><span
                            class="milk-li-content">{{v.name}}</span> <span
                            class="milk-li-suffix">({{v.articleCount}})</span></li>
                </ul>
            </section>

            <section class="one-plug">
                <h2>这里比较热闹</h2>
                <ArticleCardSimple v-for="article in hotArticle"
                                     :value="article"
                                     :key="article._id"
                ></ArticleCardSimple>
            </section>

            <section class="one-plug">
                <h2>标签云</h2>
                <Tag v-for="(v,i) in tags" :key="i" :tag="v"></Tag>
            </section>

            <section class="one-plug">
                <h2>归档</h2>
            </section>

        </div>
    </div>
</template>

<script>
  import { GetAllCategory, GetHotArticle, GetTopTag } from '@/api/blog-api'

  export default {
    name: 'Plugs',
    data: () => ({
      searchKey: '',
      categoryList: [],
      tags: [],
      hotArticle: []
    }),
    created () {
      this.getAllCategory()
      this.getTopTag()
      this.getHotArticle()
    },
    methods: {
      getAllCategory () {
        GetAllCategory().then(res => {
          this.categoryList = res.data
        }).catch(err => {
          console.log(err)
        })
      },
      getTopTag () {
        GetTopTag().then(res => {
          this.tags = res.data
        }).catch(err => {
          console.log(err)
        })
      },
      getHotArticle () {
        GetHotArticle({ limit: 6 }).then(res => {
          this.hotArticle = res.data
        }).catch(err => {
          console.log(err)
        })
      }
    }
  }
</script>

<style>
    .plug-container {
        position: relative;
        /*min-height: 100%;*/
        padding: 48px 14px;
        /*background-color: #f8f9fa;*/
    }

    .plug-container h3 {
        color: #6a6a6a;
    }

    .plug-wrapper {
        width: 100%;
        margin: 0 auto;
    }

    /*列表 START*/
    .milk-li {
        position: relative;
        height: 30px;
        font-size: 14px;
        line-height: 20px;
        font-weight: 400;
        color: #575757;
        padding-bottom: 10px;
        margin-bottom: 10px;
        border-bottom: 1px solid #dbdfe3;
    }

    .milk-li-content {
        display: inline-block;
        cursor: pointer;
        width: 100%;
        transition: 0.2s ease-in-out;
    }

    .milk-li-content:hover {
        transform: translateX(7px);
    }

    .milk-li-suffix {
        position: absolute;
        font-size: 12px;
        right: 7px;
        top: 0;
        height: 20px;
        text-align: center;
    }

    /*列表 END*/

    .one-plug {
        position: relative;
        margin-top: 24px;
        padding: 10px 30px 20px 24px;
        /*BFC*/
        overflow: hidden;
        border-radius: 8px;
        /*background-color: #f2f7fc;*/
        background-color: #FFFFFF;
        box-shadow: 0 0 2rem 0 rgba(136, 152, 170, .15);
    }

    .one-plug > h2 {
        position: relative;
        margin-bottom: 24px;
        /*margin-left: -10px;*/
    }

    .one-plug > h2::before {
        content: '';
        position: absolute;
        width: 34px;
        height: 3px;
        background-color: #54b3ea;
        left: 0;
        bottom: -14px;

    }


    /*1200px 以上 plug-container 在右边*/
    @media (min-width: 1200px) {
        .plug-container {
            flex: 1;
        }
    }
</style>
